package com.example.elm_server_api.controller;

import com.example.elm_server_api.domain.UserAddress;
import com.example.elm_server_api.domain.UserMsg;
import com.example.elm_server_api.service.IUserAddressService;
import com.example.elm_server_api.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/api")
@CrossOrigin
public class UserController {
    @Autowired
    IUserService userService;

    @Autowired
    IUserAddressService userAddressService;

    @PostMapping("/login")
    public UserMsg login(UserMsg userMsg, HttpServletRequest request, HttpSession session) {
        /*UserMsg logUser = this.userService.selectByLogin(userMsg);
        if (logUser != null) {
            return logUser;
        } else {
            return null;
        }*/
        return this.userService.selectByLogin(userMsg);


    }

    @PostMapping("/address")
    public UserAddress find(Long id) {
        return this.userAddressService.selectByPrimaryKey(id);
    }
}
